package cn.stylefeng.guns.modular.bms.controller;

import cn.stylefeng.guns.base.pojo.node.ZTreeNode;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.bms.entity.BmsIndustry;
import cn.stylefeng.guns.modular.bms.model.params.BmsIndustryParam;
import cn.stylefeng.guns.modular.bms.service.BmsIndustryService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 行业信息表控制器
 *
 * @author yzb
 * @Date 2021-03-22 23:27:17
 */
@Controller
@RequestMapping("/bmsIndustry")
public class BmsIndustryController extends BaseController {

    private String PREFIX = "/bms/bmsIndustry";

    @Autowired
    private BmsIndustryService bmsIndustryService;

    /**
     * 跳转到主页面
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/bmsIndustry.html";
    }

    /**
     * 新增页面
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/bmsIndustry_add.html";
    }

    /**
     * 编辑页面
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/bmsIndustry_edit.html";
    }

    /**
     * 新增接口
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BmsIndustryParam bmsIndustryParam) {
        this.bmsIndustryService.add(bmsIndustryParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BmsIndustryParam bmsIndustryParam) {
        this.bmsIndustryService.update(bmsIndustryParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BmsIndustryParam bmsIndustryParam) {
        this.bmsIndustryService.delete(bmsIndustryParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BmsIndustryParam bmsIndustryParam) {
        BmsIndustry detail = this.bmsIndustryService.getById(bmsIndustryParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author yzb
     * @Date 2021-03-22
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BmsIndustryParam bmsIndustryParam) {
        return this.bmsIndustryService.findPageBySpec(bmsIndustryParam);
    }


    /**
     * 获取列表（s树形）
     */
    @RequestMapping(value = "/listTree")
    @ResponseBody
    public Object listTree(BmsIndustryParam entity) {
        List<Map<String, Object>> menus = this.bmsIndustryService.selectIndustryTree(entity);
        LayuiPageInfo result = new LayuiPageInfo();
        result.setData(menus);
        return result;
    }


    /**
     * 获取树状列表
     *
     */
    @ResponseBody
    @RequestMapping(value = "/industryTreeList")
    public List<ZTreeNode> industryTreeList() {
        List<ZTreeNode> postTreeList = this.bmsIndustryService.industryTreeList();
        postTreeList.add(ZTreeNode.createParent());
        return postTreeList;
    }


}


